package com.crm.approval.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.crm.model.FinanceApprove;
import com.crm.model.SysUser;
import com.crm.service.FinanceAccraditationService;
import com.crm.util.JsonUtil;
import com.crm.util.ResponseUtil;
import com.crm.util.SessionModel;
import com.crm.util.SessionUtils;

@Controller
@RequestMapping("/accraditation")
public class FinanceAccraditationController {
	@Autowired
	private FinanceAccraditationService  accraditationService;
	
	@RequestMapping("/index")
	public String index(HttpServletRequest request){
		SysUser sysUser= ((SysUser)SessionUtils.get(SessionModel.SESSION_USER));
		request.setAttribute("user", sysUser);
		return "approval/accraditation";
	}
	

	@RequestMapping("/addNewRecord")
	@ResponseBody
	public Map<String, Object> addNewRecord(FinanceApprove record){
		
		Map<String, Object> map = new HashMap<>();
		
		accraditationService.insert(record);
		
		map.put("status", "success");
		map.put("msg", "新增成功！");
		
		return map;
	}
	@RequestMapping("/getApproveFlow/{applyId}")
	public void getApproveFlow(HttpServletResponse response,@PathVariable("applyId")String applyId){
		List<FinanceApprove> approveList =accraditationService.getApproveFlowByApplyId(applyId);
		ResponseUtil.result(response, JsonUtil.toJsonStr(approveList));
	}
}
